﻿using Authority.Common;
using Authority.EFRepositoryImpl;
using HelperFromTheSkeleton.ExtendMethod;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace Authority.DependencyInjection
{
    public static class AuthorityDI
    {
        public static void AddAuthorityServer(this IServiceCollection serviceDescriptors)
        {
            serviceDescriptors.AddDbContext<AuthorityDbContext>(
                m =>
                {
                    m.UseSqlServer(AuthorityConfig.ConfigData?.SqlConnectionString);
                    m.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
                }, ServiceLifetime.Scoped);
            serviceDescriptors.AddTransient<IUnitWork,UnitWorkImpl>();
            serviceDescriptors.AddAssembly("Authority.ServiceImpls", "ServiceImp");
            serviceDescriptors.AddAssembly("Authority.EFRepositoryImpl", "RepositoryImpl"); 
            serviceDescriptors.AddAutoMapper("Authority.ServiceImpls", "Profile");
        }
    }
}